package com.zimi.controller;

import com.zimi.model.WfSystask;
import com.zimi.model.WfSystaskVO;
import com.zimi.service.WfSystaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("流程节点")
@RestController
@RequestMapping("wf/systask")
public class WfSystaskApi {

    @Autowired
    private WfSystaskService service;

    @PostMapping("list")
    @ApiOperation("查询所有")
    public List<WfSystask> selectAll(WfSystask record) {
        return service.selectAll(record);
    }

    @PostMapping("findById")
    @ApiOperation("根据Id查询信息")
    public Object selectByPrimaryKey(int id) {
        WfSystask wfSystask = service.selectByPrimaryKey(id);
        Map map = new HashMap();
        map.put("OK", "OK");
        map.put("wfSystask", wfSystask);
        map.put("code", "200");
        return map;
    }

    @PostMapping("del/{id}")
    @ApiOperation("根据Id删除")
    public boolean deleteByPrimaryKey(@PathVariable("id") int id) {
        return service.deleteByPrimaryKey(id) > 0 ? true : false;
    }

    @PostMapping("add")
    @ApiOperation("添加")
    public boolean insert(WfSystask record) {
        return service.insertSelective(record) > 0 ? true : false;
    }

    @PostMapping("update")
    @ApiOperation("根据条件修改信息")
    public boolean updateByPrimaryKey(WfSystask record) {
        return service.updateByPrimaryKeySelective(record) > 0 ? true : false;
    }

    @PostMapping("listTimeLine")
    @ApiOperation("查询时间线")
    public Object listTimeLine(WfSystaskVO wfSysTaskVO) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("List", service.getTimeLine(wfSysTaskVO));
        map.put("OK", "OK");
        map.put("code", 200);
        return map;
    }

    @PostMapping("listWfSystaskAndWfTask")
    @ApiOperation("查询所有")
    public Object listWfSystaskAndWfTask(WfSystask record) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("sysTasks", service.selectAll(record));
        map.put("OK", "OK");
        map.put("code", 200);
        return map;
    }

}
